home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / comm / tcp / AmiTCPsdk_40.lha / AmiTCP-4.0 / netinclude / charread.h < prev    next >
C/C++ Source or Header  |  1994-10-14  |  1KB  |  53 lines

  1. #ifndef CHARREAD_H
  2. #define CHARREAD_H \
  3.        "$Id: charread.h,v 4.2 1994/10/14 17:10:35 too Exp $"
  4. /*
  5.  *      Macros for efficient interface to socket receiving
  6.  *
  7.  *      Copyright © 1994 AmiTCP/IP Group, Network Solutions Development, Inc.
  8.  *                       All rights reserved.
  9.  */
  10.  
  11.  
  12. #ifndef RC_BUFSIZE
  13. #define RC_BUFSIZE 1024
  14. #endif
  15.  
  16. struct CharRead {
  17.   int    rc_Fd;
  18.   int    rc_Size;
  19.   int    rc_Curr;
  20.   unsigned char    rc_Buffer[RC_BUFSIZE];
  21. };
  22.  
  23. #define RC_DO_SELECT    -3
  24. #define RC_EOF        -2
  25. #define RC_ERROR    -1
  26.  
  27. #define initCharRead(rc, fd) do { \
  28.                   (rc)->rc_Fd = fd;  \
  29.                       (rc)->rc_Size = 0; \
  30.                   (rc)->rc_Curr = 1; \
  31.                  } while(0)
  32.  
  33. #ifdef AMIGA
  34. #define RC_R_E_A_D(a, b, c) recv(a, b, c, 0)
  35. #else
  36. #define RC_R_E_A_D(a, b, c) read(a, b, c)
  37. #endif
  38.  
  39. #define charRead(rc) \
  40.     ((rc)->rc_Curr >= (rc)->rc_Size ? \
  41.         (rc)->rc_Curr++ == (rc)->rc_Size ? \
  42.             RC_DO_SELECT: \
  43.             ((rc)->rc_Size = RC_R_E_A_D((rc)->rc_Fd, \
  44.                             (rc)->rc_Buffer, \
  45.                             RC_BUFSIZE)) <= 0 ? \
  46.                 (rc)->rc_Size == 0 ? \
  47.                     RC_EOF:    \
  48.                     RC_ERROR: \
  49.                 (rc)->rc_Buffer[((rc)->rc_Curr = 1) - 1]: \
  50.             (rc)->rc_Buffer[(rc)->rc_Curr++])
  51.  
  52. #endif /* _CHARREAD_H_ */
  53.